<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{layui/css/layui.css}" media="all">
</head>
<style type="text/css">
    .layui-table-cell {
        height: 100px;
        /*line-height: 28px;*/
        padding: 0 15px;
        position: relative;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        box-sizing: border-box;
        vertical-align: middle;
        text-align: center;
    }

    .layui-table img {
        max-width: 100px;
        max-height: 100px;
        margin-top: 10px;
    }
    .layui-form-item {
        margin-bottom: 15px;
        clear: both;
        *zoom: 1;
        margin-left: -80px;
    }
</style>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="queryGuiGe">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="doWithdarals">处理提现</a>
</script>
<script type="text/html" id="bar-upstate">
    <div class="layui-form-item" pane="">
        <div class="layui-input-block">
            <input type="checkbox" name="productUpState" lay-skin="primary" title="上架" checked="">
            <input type="checkbox" name="productUpState" lay-skin="primary" title="下架">
        </div>
    </div>
</script>


<script th:src="@{layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<script type="application/javascript" th:src="@{/shoppingApi/js/common.js}"></script>
<script th:inline="none">
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test'
            , url: '/getWithdrawalsList'
            , cellMinWidth: 80
            , toolbar: '#toolbarDemo'
            , title: '用户数据表'
            , totalRow: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'userId', title: '用户ID'}
                , {field: 'userName', title: '用户真名'}
                , {field: 'phone', title: '用户电话'}
                , {field: 'cardId', title: '用户身份证号'}
                , {field: 'name', title: '用户名'}
                , {field: 'userNo', title: '用户编号'}
                , {field: 'id', title: '提现编号'}
                , {field: 'account', title: '账户'}
                , {field: 'bankName', title: '支行名称'}
                , {field: 'cashCount', title: '提现金额'}
                , {field: 'applyTime', title: '申请时间', templet: '<div>{{ Format(d.applyTime,"yyyy-MM-dd hh:mm:ss")}}</div>'}
                , {field: 'tixianSign', title: '提现状态',templet: '<div>{{d.tixianSign=="1"?"申请提现":"已处理"}}</div>'}
                , {field: 'opTime', title: '处理时间', templet: '<div>{{ Format(d.opTime,"yyyy-MM-dd hh:mm:ss")}}</div>'}
                , {field: 'opratorId', title: '处理人'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
            ]]
            , page: true

        });

        //处理提现
        table.on('tool(test)', function (obj) {

            var data = obj.data;
            var tixianSign1=data.tixianSign;
            var ids=data.id;
                if(tixianSign1=='0'){
                    tixianSign1='已处理';
                }else if(tixianSign1=='1'){
                    tixianSign1='申请提现';
                }
            if (obj.event === 'doWithdarals') {
                layer.prompt({
                    formType: 3
                    ,value: tixianSign1
                }, function(value, index){
                    obj.update({
                        tixianSign: value
                    });

                    //更新提现状态
                    updateWithDrawals(ids,'0');
                    layer.close(index);
                    
                });

            }

        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;
            }
            ;
        });

        //复选框
        table.on('checkbox(test)', function(obj){
            console.log(obj.checked); //当前是否选中状态
            console.log(obj.data); //选中行的相关数据
            console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
        });

    });

    function Format(datetime, fmt) {
        if (parseInt(datetime) == datetime) {
            if (datetime.length == 10) {
                datetime = parseInt(datetime) * 1000;
            } else if (datetime.length == 13) {
                datetime = parseInt(datetime);
            }
        }
        datetime = new Date(datetime);
        var o = {
            "M+": datetime.getMonth() + 1,                 //月份
            "d+": datetime.getDate(),                    //日
            "h+": datetime.getHours(),                   //小时
            "m+": datetime.getMinutes(),                 //分
            "s+": datetime.getSeconds(),                 //秒
            "q+": Math.floor((datetime.getMonth() + 3) / 3), //季度
            "S": datetime.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (datetime.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    
    //更新提现
   function  updateWithDrawals(id,tixianSign) {
       $.ajax({
           type:'post',
           url:'/updateWithDrawals',
           data:{
               id:id,
               tixianSign:tixianSign
           },
           success:function (res) {
                if(res.msg=='1'){
                    layer.msg('处理成功！');
                }else{
                    layer.msg('处理成功！');
                }
           }

       })
   } 

</script>

</body>

</html>